package com.ruoyi.web.controller.basedata;

import com.ruoyi.basedata.domain.DosageRange;
import com.ruoyi.basedata.service.IDosageRangeService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用量区间设置Controller
 * 
 * @author ruoyi
 * @date 2023-09-07
 */
@RestController
@RequestMapping("/basedata/dosagerange")
public class DosageRangeController extends BaseController
{
    @Autowired
    private IDosageRangeService dosageRangeService;

    /**
     * 查询用量区间设置列表
     */
    @PreAuthorize("@ss.hasPermi('basedata:dosagerange:list')")
    @GetMapping("/list")
    public TableDataInfo list(DosageRange dosageRange)
    {
        startPage();
        List<DosageRange> list = dosageRangeService.selectDosageRangeList(dosageRange);
        return getDataTable(list);
    }

    /**
     * 导出用量区间设置列表
     */
    @PreAuthorize("@ss.hasPermi('basedata:dosagerange:export')")
    @Log(title = "用量区间设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DosageRange dosageRange)
    {
        List<DosageRange> list = dosageRangeService.selectDosageRangeList(dosageRange);
        ExcelUtil<DosageRange> util = new ExcelUtil<DosageRange>(DosageRange.class);
        util.exportExcel(response, list, "用量区间设置数据");
    }

    /**
     * 获取用量区间设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('basedata:dosagerange:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dosageRangeService.selectDosageRangeById(id));
    }

    /**
     * 新增用量区间设置
     */
    @PreAuthorize("@ss.hasPermi('basedata:dosagerange:add')")
    @Log(title = "用量区间设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DosageRange dosageRange)
    {
        return toAjax(dosageRangeService.insertDosageRange(dosageRange));
    }

    /**
     * 修改用量区间设置
     */
    @PreAuthorize("@ss.hasPermi('basedata:dosagerange:edit')")
    @Log(title = "用量区间设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DosageRange dosageRange)
    {
        return toAjax(dosageRangeService.updateDosageRange(dosageRange));
    }

    /**
     * 删除用量区间设置
     */
    @PreAuthorize("@ss.hasPermi('basedata:dosagerange:remove')")
    @Log(title = "用量区间设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dosageRangeService.deleteDosageRangeByIds(ids));
    }
}
